<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../libs/bootstrap-3.3.0/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/lib.css" />
    <link rel="stylesheet" type="text/css" href="../../styles/common.css" />
    <script src="../../js/jquery-3.2.1.min.js"></script>
    <script src="../../js/jquery.formHelp.js"></script>
</head>
<body>
<div class="definewidth m20">
    <button type="button" class="btn btn-success" id="addnew">新增</button>
    <button type="button" class="btn btn-danger" id="delect">删除</button>
    <button type="button" class="btn btn-primary" id="backbtn">返回</button>
    <table class="table table-bordered table-hover m10" id="table">
    </table>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="modalUser">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form id="form">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">参数管理</h4>
                </div>
                <div class="modal-body">
                    <form class="form">
                        <div class="form-group fix">
                            <div class="input-group w300 mt10">
                                <div class="input-group-addon">参数名称</div>
                                <input type="text" class="form-control" id="paramName" name="paramName">
                                <div class="required-icon">*</div>
                            </div>
                            <div class="input-group w300 mt10">
                                <div class="input-group-addon">参数值</div>
                                <input type="text" class="form-control" id="paramValue" name="paramValue">
                                <div class="required-icon">*</div>
                            </div>
                            <div class="input-group w300 mt10 hidden">
                                <div class="input-group-addon">id</div>
                                <input type="text" class="form-control" id="paramId" name="paramId">
                                <input type="text" class="form-control" id="createDate" name="createDate">
                                <input type="text" class="form-control" id="isValid" name="isValid" value="true">
                                <input type="text" class="form-control" id="paramTypeId" name="paramTypeId">
                            </div>
                            <div class="input-group mt10">
                                <div class="input-group-addon">参数描述</div>
                                <textarea class="form-control" rows="3" id="description" name="description"></textarea>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="submintBtn">保存</button>
                    <button type="button" class="btn btn-primary" id="submintBtn2">保存</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script type="text/javascript" src="../../libs/bootstrap-3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../libs/bootstrap-table/bootstrap-table.min.js"></script>
<script type="text/javascript" src="../../libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<link rel="stylesheet" type="text/css" href="../../libs/bootstrap-table/bootstrap-table.min.css" />
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/validateform.js"></script>
<script type="text/javascript" src="paramlist.js?t=20170801"></script>
<script type="text/javascript">
    var typeVal = getQueryString('typeVal')
    var typeId = getQueryString('id')
//    $.ajax({
//        type: "POST",
//        url: ctx + "/parameter/queryParameterType",
//        success: function(data){
//            if(data.code == 200){
//                setOption('#parentId', data.list)
//            }
//        }
//    });

    $("#backbtn").click(function () {
        window.location.href = "list.html";
    });

    var formdata = '';
    $('#addnew').click(function () {
        $('#modalUser').modal({backdrop: 'static', keyboard: false});
        $("#submintBtn2").hide()
        $("#submintBtn").show()
        $("#paramName").val('')
        $("#paramId").val('')
        $("#paramValue").val('')
        $("#paramTypeId").val('')
        $("#description").val('')
        $("#createDate").val('')
        $("#paramName").removeAttr('disabled')
        $("#paramId").removeAttr('disabled')
        $("#paramValue").removeAttr('disabled')
        $("#paramTypeId").removeAttr('disabled')
        $("#description").removeAttr('disabled')
        $("#createDate").removeAttr('disabled')
    })
    $("#submintBtn").click(function () {
        if($("#form").valid()){
            $("#paramTypeId").val(typeId)
            formdata = $("#form").serializeJson()
            $.ajax({
                type: 'POST',
                url: ctx + "/parameter/insertParameter",
                contentType: "application/json",
                dataType: 'json',
                data: JSON.stringify(formdata),
                success: function(data){
                    if(data.code==200){
                        $('#modalUser').modal('hide')
                        $('#table').bootstrapTable('refresh', {url: ctx + '/parameter/queryByParameterType'});
                    }else{
                        alert(data.msg);
                    }

                }
            })
        }
    })
    $("#submintBtn2").click(function () {
        if($("#form").valid()){
            $("#paramTypeId").val(typeId)
            formdata = $("#form").serializeJson()
            $.ajax({
                type: 'POST',
                url: ctx + "/parameter/update",
                contentType: "application/json",
                dataType: 'json',
                data: JSON.stringify(formdata),
                success: function(data){
                    $('#modalUser').modal('hide')
                    $('#table').bootstrapTable('refresh', {url: ctx + '/parameter/queryByParameterType'});
                }
            })
        }
    })
    $("#delect").click(function () {
        var selRow = $('#table').bootstrapTable('getSelections');
        if (selRow.length==0) {
            alert('没有选中记录');
        }else {
            if (confirm("确定删除？")) {
                var selIds = [];
                $(selRow).each(function (i, row) {
                    selIds.push(row.paramId);
                });
                $.ajax({
                    type: "POST",
                    url: ctx + "/parameter/deleteParameterByList",
                    traditional: true,
                    data: {
                        ids: selIds
                    },
                    success: function (data) {
                        $('#table').bootstrapTable('refresh', {url: ctx + '/parameter/queryByParameterType'});
                    }
                })
            }
        }
    })

    function setOption(id, param){
        var html = '';
        html +='<option value="">请选择</option>';
        for (var i =0;i<param.length;i++){
            html +='<option value="'+ param[i].paramTypeId +'">'+ param[i].paramTypeName +'</option>';
        }
        $(id).append(html);
    }
</script>
</body>
</html>